Minort QString-ificaion of google.cc
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 12 Oct 2014 02:17:07 +0000 (02:17 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 12 Oct 2014 02:17:07 +0000 (02:17 +0000)
gpsbabel/google.cc

index cd196b2834cfafe1e985b8320639d04953fbe5e9..1cd22aaa622822a6fcc96498a51308bf8466382e 100644 (file)
@@ -25,7 +25,7 @@
 
 static char* encoded_points = NULL;
 static char* encoded_levels = NULL;
-static char* script = NULL;
+static QString script;
 static route_head** routehead;
 static int* routecount;
 static short_handle desc_handle;
@@ -58,11 +58,7 @@ xg_tag_mapping google_map[] = {
 
 void goog_script(xg_string args, const QXmlStreamAttributes*)
 {
-  if (script) {
-    script = xstrappend(script, CSTRc(args));
-  } else {
-    script = xstrdup(args);
-  }
+  script += args;
 }
 
 
@@ -86,7 +82,7 @@ void goog_levels(xg_string args, const QXmlStreamAttributes*)
 }
 
 static char goog_segname[7];
-static char* goog_realname = NULL;
+static QString goog_realname;
 static int goog_segroute = 0;
 
 /*
@@ -152,24 +148,17 @@ void goog_td_s(xg_string args, const QXmlStreamAttributes* attrv)
 void goog_td_b(xg_string args, const QXmlStreamAttributes*)
 {
   if (goog_segname[0] == '\\' && !strchr(CSTRc(args), '\xa0')) {
-    if (goog_realname) {
-      xfree(goog_realname);
-      goog_realname = NULL;
-    }
-    goog_realname = (char*) xmalloc(strlen(CSTRc(args))+1);
-    strcpy(goog_realname, CSTRc(args));
+    goog_realname = args;
   }
 }
+
 void goog_td_e(xg_string args, const QXmlStreamAttributes*)
 {
-  if (goog_segname[0] == '\\' && goog_realname) {
+  if (goog_segname[0] == '\\' && !goog_realname.isEmpty()) {
     goog_segment(goog_realname, NULL/*unused*/);
   }
   goog_segname[0] = '\0';
-  if (goog_realname) {
-    xfree(goog_realname);
-    goog_realname = NULL;
-  }
+  goog_realname.clear();
 }
 
 static long decode_goog64(char** str)
@@ -311,10 +300,11 @@ google_read(void)
     xfree(encoded_levels);
     encoded_levels = NULL;
   }
-  if (script) {
-    char* xml = strchr(script, '\'');
-    char* dict = strstr(script, "({");
-
+  if (!script.isEmpty()) {
+    // TODO: rethink with Qt to make this less dependent on strchr...
+    char* s = xstrdup(script);
+    char* xml = strchr(s, '\'');
+    char* dict = strstr(s, "({");
     char* end = NULL;
 
     if (xml && (!dict || (xml < dict))) {
@@ -519,10 +509,10 @@ google_read(void)
         }
       }
     }
-    xfree(script);
+    script.clear();
     xfree(routehead);
     xfree(routecount);
-    script = NULL;
+    xfree(s);
   }
 
   /*